package org.ithang.application.invest;

import org.ithang.tools.model.Action;
import org.ithang.tools.model.ActionResult;
import org.ithang.tools.model.ActionValues;
import org.ithang.tools.model.Pager;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import org.springframework.ui.Model;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.ithang.application.customer.bean.Customer;
import org.ithang.application.invest.bean.Invest;
import org.ithang.application.invest.service.InvestService;

/**
 * 投资表
 * @author zyt 控制器
 *
 */
@Controller
@RequestMapping("/app/invest")
public class InvestAction extends Action<Invest>{

    @Autowired
    private InvestService investService; 


    @ResponseBody
	@RequestMapping(value="add",method=RequestMethod.POST)
	public ActionResult add(Invest invest){
		investService.add(invest);
		return success();
	}
	
	 @RequestMapping("form")
    public String form(@RequestParam(value="id",required=false)Integer id,Model m){
    	if(null!=id){
    		Invest bean=investService.get(id);
    		m.addAttribute(bean);
    	}else{
    		m.addAttribute(new Invest());
    	}
    	return "app/invest/form";
    }
	
	
	@ResponseBody
	@RequestMapping(value="update",method=RequestMethod.POST)
	public ActionResult update(Invest invest){
		investService.update(invest);
		return success();
	}


    @ResponseBody
	@RequestMapping(value="get",method=RequestMethod.GET)
	public ActionResult get(Integer id){
		Invest r=investService.get(id);
		return success(r);
	}
	
	@ResponseBody
	@RequestMapping(value="delete",method=RequestMethod.POST)
	public ActionResult delete(@RequestParam(value="id",required=false)Integer id,@RequestParam(value="ids",required=false)String ids){
		
		if(null!=id&&id>0){
			investService.delete(id);	
		}
		
		if(null!=ids&&ids.length()>0){
			investService.batchDelete(ids.split(","));
		}
		
		return success();
	}
	
	@ResponseBody
	@RequestMapping(value="list",method={RequestMethod.GET,RequestMethod.POST})
	public ActionResult list(Integer... ids){
		return success(investService.list(ids));
	}
	
	@ResponseBody
	@RequestMapping(value="page",method=RequestMethod.POST)
	public ActionResult page(Invest invest,Pager<Invest> page){
	    page.setBean(invest);
	    List<Invest> data=investService.page(page);
	    page.setData(data);
		return success(page);
	}
	
	@ResponseBody
	@RequestMapping(value="query",method=RequestMethod.POST)
	public ActionResult query(HttpServletRequest request){
		ActionValues values=new ActionValues(request);
		return success(investService.query(values));
	}
     

}